package com.phantasy.ui.skins
{
	import com.phantasy.core.IDisposable;
	import com.phantasy.utils.ScaleBitmap;
	
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	/**
	 *皮肤 
	 * @author Liseen
	 * 
	 */	
	public class Skin extends Sprite implements IDisposable
	{
		private var _enableMouse:Boolean = true;
		private var _skinBitmapData:BitmapData;
		private var _rect:Rectangle;
		private var _skinInstance:ScaleBitmap;
		/**
		 *skin构造 
		 * @param bitmapData	位图图源
		 * @param rectangle		9切片矩形
		 * 
		 */		
		public function Skin(bitmapData:BitmapData=null, rectangle:Rectangle=null)
		{
			if(bitmapData!=null){
				_rect = rectangle;
				skinBitmapData = bitmapData;
				this.mouseChildren = this.mouseEnabled = false;
			}
		}
		/**
		 *写皮肤实例 
		 * @param scaleBitmap	9切片位图
		 * 
		 */		
		public function set skinInstance(scaleBitmap:ScaleBitmap):void
		{
			this._skinInstance = scaleBitmap;
		}
		
		public function get skinInstance():ScaleBitmap
		{
			return this._skinInstance;
		}
		
		public function get enableMouse():Boolean
		{
			return this._enableMouse;
		}
		/**
		 *设置鼠标是否可用 
		 * @param value
		 * 
		 */		
		public function set enableMouse(value:Boolean):void
		{
			this._enableMouse = value;	
		}
		
		override public function set width(value:Number):void
		{
			if (this.skinInstance == null)
			{
				return;
			}
			this.skinInstance.width = value;
		}
		
		override public function get width():Number
		{
			if (this.skinInstance == null)
			{
				return 0;
			}
			return this.skinInstance.width;
		}
		/**
		 *设置尺寸 
		 * @param width		宽度
		 * @param heigth	高度
		 * 
		 */		
		public function setSize(width:Number, heigth:Number):void
		{
			if (this.skinInstance != null)
			{
				if (!(this.skinInstance.width == width) || !(this.skinInstance.height == heigth))
				{
					if (!(width == 0) && !(heigth == 0))
					{
						this.skinInstance.setSize(width, heigth);
					}
				}
			}
		}
		
		override public function set height(value:Number):void
		{
			if (this.skinInstance == null)
			{
				return;
			}
			this.skinInstance.height = value;
		}
		
		override public function get height():Number
		{
			if (this.skinInstance == null)
			{
				return 0;
			}
			return this.skinInstance.height;
		}
		
		public function set skinBitmapData(bitmapData:BitmapData):void
		{
			dispose();
			_skinBitmapData = bitmapData;
			this.skinInstance = new ScaleBitmap(this._skinBitmapData);
			this.skinInstance.x = 0;
			this.skinInstance.y = 0;
			this.skinInstance.scale9Grid = this._rect;
			addChild(this.skinInstance);
		}
		
		public function dispose():void
		{
		}
	}
}